package com.nft.config;

import com.nft.po.NftResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Demo class
 *
 * @author keriezhang
 * @date 2016/10/31
 */
@Slf4j
@RestControllerAdvice
public class ExceptionConfig {
   /* *//**
     * 全局监听参数校验异常
     *
     * @param e
     * @return
     *//*
    @ExceptionHandler(ConstraintViolationException.class)
    public Result resolveConstraintViolationException(ConstraintViolationException e) {
        return ResultUtil.error(ReturnCode.FAIL.getCode(), e.getConstraintViolations()
                .stream()
                .findFirst()
                .map(ConstraintViolation::getMessage).orElse("参数校验失败"));
    }*/

    /**
     * 全局监听对象为空异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(value = IllegalArgumentException.class)
    public NftResponse illegalArgumentExceptionHandler(IllegalArgumentException e) {
        return NftResponse.builderError(e.getMessage());
    }

    /**
     * 全局监听异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public NftResponse exceptionHandler(Exception e) {
        log.error("ERROR", e);
        return NftResponse.builderError(e.getMessage());
    }

}